
#ifndef __WINDOWS_LIB_H__
#define __WINDOWS_LIB_H__

#import "protocol.h"
#import <Foundation/Foundation.h>
//#import "Timer.h"
#define APP_ERROR_CHECK(ERR_CODE)                           \
	do                                                      \
	{                                                       \
	const uint32_t LOCAL_ERR_CODE = (ERR_CODE);         \
	if (LOCAL_ERR_CODE != NRF_SUCCESS)                  \
		{                                                   \
		printf("app error check: %d\r\n", ERR_CODE);              \
		}                                                   \
	} while (0)  

#define APP_TIMER_TICKS(x,y)	x
#define APP_TIMER_PRESCALER		1

#define	SECOND_PER_DAY             86400UL  // 24 hours * 60 minutes * 60 seconds

typedef enum
{
	APP_TIMER_MODE_SINGLE_SHOT,                 /**< The timer will expire only once. */
	APP_TIMER_MODE_REPEATED                     /**< The timer will restart each time it expires. */
} app_timer_mode_t;
typedef void(^BLECallBack)(BOOL isTimeOut);
typedef uint64_t UINT_PTR;
typedef UINT_PTR app_timer_id_t;

/**@brief Application timeout handler type. */
typedef void (*app_timer_timeout_handler_t)(void * p_context);

/**@brief Type of function for passing events from the timer module to the scheduler. */
typedef uint32_t (*app_timer_evt_schedule_func_t) (app_timer_timeout_handler_t timeout_handler,
												   void *                      p_context);

//uint32_t app_timer_create(app_timer_id_t *            p_timer_id,
//						  app_timer_mode_t            mode,
//						  app_timer_timeout_handler_t timeout_handler);
//uint32_t app_timer_start(app_timer_id_t timer_id, uint32_t timeout_ticks, void * p_context);
//uint32_t app_timer_stop(app_timer_id_t timer_id);
//uint32_t app_query_timer(app_timer_id_t timer_id);
uint32_t ble_nus_send_string(uint8_t * str, uint16_t *length, BLECallBack callback);

// config.h
#define GLOBAL_RECEIVE_BUFFER_SIZE          1024
#define GLOBAL_RESPONSE_BUFFER_SIZE         200

// app_error.h
#define NRF_ERROR_BASE_NUM      (0x0)       ///< Global error base
#define NRF_ERROR_SDM_BASE_NUM  (0x1000)    ///< SDM error base
#define NRF_ERROR_SOC_BASE_NUM  (0x2000)    ///< SoC error base
#define NRF_ERROR_STK_BASE_NUM  (0x3000)    ///< STK error base

#define NRF_SUCCESS                           (NRF_ERROR_BASE_NUM + 0)  ///< Successful command
#define NRF_ERROR_SVC_HANDLER_MISSING         (NRF_ERROR_BASE_NUM + 1)  ///< SVC handler is missing
#define NRF_ERROR_SOFTDEVICE_NOT_ENABLED      (NRF_ERROR_BASE_NUM + 2)  ///< SoftDevice has not been enabled
#define NRF_ERROR_INTERNAL                    (NRF_ERROR_BASE_NUM + 3)  ///< Internal Error
#define NRF_ERROR_NO_MEM                      (NRF_ERROR_BASE_NUM + 4)  ///< No Memory for operation
#define NRF_ERROR_NOT_FOUND                   (NRF_ERROR_BASE_NUM + 5)  ///< Not found
#define NRF_ERROR_NOT_SUPPORTED               (NRF_ERROR_BASE_NUM + 6)  ///< Not supported
#define NRF_ERROR_INVALID_PARAM               (NRF_ERROR_BASE_NUM + 7)  ///< Invalid Parameter
#define NRF_ERROR_INVALID_STATE               (NRF_ERROR_BASE_NUM + 8)  ///< Invalid state, operation disallowed in this state
#define NRF_ERROR_INVALID_LENGTH              (NRF_ERROR_BASE_NUM + 9)  ///< Invalid Length
#define NRF_ERROR_INVALID_FLAGS               (NRF_ERROR_BASE_NUM + 10) ///< Invalid Flags
#define NRF_ERROR_INVALID_DATA                (NRF_ERROR_BASE_NUM + 11) ///< Invalid Data
#define NRF_ERROR_DATA_SIZE                   (NRF_ERROR_BASE_NUM + 12) ///< Data size exceeds limit
#define NRF_ERROR_TIMEOUT                     (NRF_ERROR_BASE_NUM + 13) ///< Operation timed out
#define NRF_ERROR_NULL                        (NRF_ERROR_BASE_NUM + 14) ///< Null Pointer
#define NRF_ERROR_FORBIDDEN                   (NRF_ERROR_BASE_NUM + 15) ///< Forbidden Operation
#define NRF_ERROR_INVALID_ADDR                (NRF_ERROR_BASE_NUM + 16) ///< Bad Memory Address
#define NRF_ERROR_BUSY                        (NRF_ERROR_BASE_NUM + 17) ///< Busy

// ble_nus.h
#define NUS_MAX_DATA_LENGTH             20

// nrf_error.h

/* @defgroup BLE_ERRORS Error Codes
 * @{ */
#define BLE_ERROR_INVALID_CONN_HANDLE    (NRF_ERROR_STK_BASE_NUM+0x001) /**< Invalid connection handle. */
#define BLE_ERROR_INVALID_ATTR_HANDLE    (NRF_ERROR_STK_BASE_NUM+0x002) /**< Invalid attribute handle. */
#define BLE_ERROR_NO_TX_BUFFERS          (NRF_ERROR_STK_BASE_NUM+0x003) /**< Buffer capacity exceeded. */
/** @} */


/** @defgroup BLE_ERROR_SUBRANGES Module specific error code subranges
 *  @brief Assignment of subranges for module specific error codes.
 *  @note For specific error codes, see ble_<module>.h or ble_error_<module>.h.
 * @{ */
#define NRF_L2CAP_ERR_BASE             (NRF_ERROR_STK_BASE_NUM+0x100) /**< L2CAP specific errors. */
#define NRF_GAP_ERR_BASE               (NRF_ERROR_STK_BASE_NUM+0x200) /**< GAP specific errors. */
#define NRF_GATTC_ERR_BASE             (NRF_ERROR_STK_BASE_NUM+0x300) /**< GATT client specific errors. */
#define NRF_GATTS_ERR_BASE             (NRF_ERROR_STK_BASE_NUM+0x400) /**< GATT server specific errors. */
/** @} */


#endif //__COMMUNICATE_PROTOCOL_H__
